import IndexBtnBox from "@/components/index/IndexBtnBox";
import IndexBtnPro from "@/components/index/IndexBtnPro";
import {getFileUrl} from "@/utils/serve/memory";
import { getAd } from "@/utils/service";
// import { formatDate } from "@/utils/ants";
import { getListClid, homeData,getInfolistByTime,getListByMonth } from "@/utils/serve/classify";
import { getListByType } from "@/utils/serve/advertising";
// import banner1 from "../../assets/images/banner1.png";
// import banner2 from "../../assets/images/banner2.png";
import {isTimeDifference} from "../../utils/common";

export default {
    name: "Index",
    data() {
        return {
            a:[
                'http://www.shibor.org/'
            ],
            value: new Date(),
            activeName: "first",
            rightName:'gsgg',
            fileRoot:'',
            indexBtnBoxData: [],
            list:[],
            rili: {
                isShow: false,
                date: "",
                datalist: "",
                monthData: ""
            },
            bannerList:[],
            tableData: [
                {
                    jjdm: "00082",
                    jjmc: "嘉实研究阿尔法",
                    dwjz: "1.7260",
                    rzdz: "0.58%",
                    jyz: "3.29%",
                    jyy: "14.91%",
                },
                {
                    jjdm: "00082",
                    jjmc: "嘉实研究阿尔法",
                    dwjz: "1.7260",
                    rzdz: "0.58%",
                    jyz: "3.29%",
                    jyy: "14.91%",
                },
                {
                    jjdm: "00082",
                    jjmc: "嘉实研究阿尔法",
                    dwjz: "1.7260",
                    rzdz: "0.58%",
                    jyz: "3.29%",
                    jyy: "14.91%",
                },
            ],
        };
    },
    components: { IndexBtnBox,IndexBtnPro },
    computed: {},
    filters: {
        ellipsis (value, long) {
            if (!value) return ''
            if (value.length > long) {
                return value.slice(0,long) + '...'
            }
            return value
        }
    },
    methods: {
        goweb(e){
            window.open(e, '_blank')
        },
        isInArray(value){
            // console.log("当前判断的日期：" + value)
            for(var i = 0; i < this.rili.monthData.length; i++){
                if(value === this.rili.monthData[i]){
                    return true;
                }
            }
            return false;
        },
        async getFileUrl(){
            let _this = this;
            _this.$store.commit("setIsLoading", true);
            await getFileUrl(res=>{
                _this.$store.commit("setIsLoading", false);
                if (res.code==0){
                    _this.fileRoot = res.data;
                }
            })
        },
        getListByType(){
            let _this = this;
            _this.$store.commit("setIsLoading", true);
            getListByType(0,0,6, res=>{
                _this.$store.commit("setIsLoading", false);
                console.log(res)
                if(res.code==0){
                    _this.bannerList = res.data;
                }
            })
        },
        goList(e){
            this.$router.push({
                name: 'ReadList',
                params: { id: e }
            });
        },
        rightClick(e){
            console.log(e)
            if(e.type==1){
                // window.location.href = "http://nz_mn_pc.xw025.com/"
                window.open(e.url, "_blank");
            }else if(e.type==2){
                this.$router.push({ name: e.url, params: { id: e.id } });
            }else if(e.type==3){
                this.$alert('<strong>这里要放一个二维码</strong>', '在线直播', {
                    dangerouslyUseHTMLString: true
                });
            }
        },
        // goTanchuang(e){
        //     if(e==1){
        //         this.$alert("<strong href='http://www.baidu.com'>SHIBOR和LPR</strong>", '请选择', {
        //             dangerouslyUseHTMLString: true
        //         });
        //     }
        // },
        mouseover(e){
            this.activeName = e
        },
        rightmouseover(e){
            this.rightName = e
        },
        goTo(e,id){
            //直接跳转
            this.$router.push({ name: e, params: { id: id } });
        },
        getListClid(id,e){
            let _this = this;
            _this.$store.commit("setIsLoading", true);
            getListClid(id, e, res => {
                _this.$store.commit("setIsLoading", false);
                if (res.code == 0) {
                    _this.list = res.data;
                }
            });
        },
        getAd() {
            getAd(1, (res) => {
                console.log(res);
                if (res.Status) {
                    this.indexBtnBoxData = res.Data;
                } else {
                    console.log(res);
                }
            });
        },
        handleClick(tab, event) {
            console.log(tab, event);
        },
        allcalendar(e) {
            console.log("选择的日期：", e);
            this.rili.isShow = true;
            this.rili.date = e;
            // todo 请求后台日历的数据
            this.getInfolistByTime(this.rili.date)
        },
        homeData(){
            let _this = this;
            _this.$store.commit("setIsLoading", true);
            homeData( res => {
                _this.$store.commit("setIsLoading", false);
                if (res.code == 0) {
                    _this.list = res.data;
                }
            });
        },
        getInfolistByTime(e){
            let _this = this;
            _this.$store.commit("setIsLoading", true);
            getInfolistByTime(e,res=>{
                _this.$store.commit("setIsLoading", false);
                if (res.code == 0) {
                    _this.rili.datalist = res.data.list;
                }
            })
        },
        isTimeDifference(stime){
            return isTimeDifference(stime, new Date(), 'H', 8)
        },
        getListByMonth(e){
            let _this = this;
            _this.$store.commit("setIsLoading", true);
            getListByMonth(e,res=>{
                _this.$store.commit("setIsLoading", false);
                if (res.code == 0) {
                    _this.rili.monthData = res.data;
                }
            })
        },
    },
    mounted() {
        // console.log(this.compareDate("2021-03-10 22:30:00"))
        // this.getAd();
        this.getFileUrl();
        this.homeData();
        var myDate = new Date();
        this.rili.date = myDate.getFullYear()+'-'+(myDate.getMonth()+1)+'-'+myDate.getDate()
        this.getInfolistByTime(this.rili.date);
        // console.log("日历", this.rili)
        this.getListByMonth(this.rili.date)
        this.getListByType()

    },
};